import babel from '@rollup/plugin-babel'
import server from 'rollup-plugin-server'
import typescript from '@rollup/plugin-typescript'
import compiler from '@ampproject/rollup-plugin-closure-compiler'

// 判断是否为开发环境
const isDevelopment = process.env.NODE_ENV === 'development'

export default {
    input: 'packages/index.ts',
    output: {
        file: 'dist/index.js',
        format: 'umd',
        name: 'TMapLoader',
        sourcemap: false
    },
    plugins: [
        typescript({
            tsconfig: './tsconfig.json',
            declaration: true,
            declarationDir: 'dist/types',
            compilerOptions: {
                module: 'ESNext'
            }
        }),
        babel({
            presets: [
                [
                    '@babel/preset-env',
                    {
                        targets: {
                            browsers: ['last 2 versions', 'ie >= 11']
                        }
                    }
                ]
            ],
            babelHelpers: 'bundled',
            extensions: ['.ts', '.js'],
            exclude: 'node_modules/**'
        }),

        compiler(),

        isDevelopment && server({
            contentBase: './',
            host: "127.0.0.1",
            port: 3000
        })
    ]
}
